﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;
using System.Net;

namespace ProjectSem3
{
    public partial class WebForm11 : System.Web.UI.Page
    {
        private dataDataContext dc = new dataDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {

            string url = "http://www.technewsworld.com/perl/syndication/rssfull.pl";
            XmlTextReader reader = new XmlTextReader(url);

            DataSet ds = new DataSet();
            ds.ReadXml(reader);

            for (int i = 0; i < ds.Tables["item"].Rows.Count; i++)
            {
                ds.Tables["item"].Rows[i]["link"] = "News_Detail.aspx?url=" + Convert.ToString(ds.Tables["item"].Rows[i]["link"]);
                ds.Tables["item"].Rows[i]["encoded"] = ds.Tables["item"].Rows[i]["encoded"].ToString().Replace("href=\"", "href=\"News_Detail.aspx?url=\"");
            }


            rptRSS.DataSource = ds.Tables["item"];
            rptRSS.DataBind();


            this.Repeater_Product.DataSource = this.dc.Products.ToList();
            this.Repeater_Product.DataBind();

        }
        protected void Repeater_Product_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HiddenField productID = e.Item.FindControl("productID") as HiddenField;
            var img = this.dc.ImagesPros.Where(i => i.ProductID == Int32.Parse(productID.Value)).Skip(0).Take(1);
            Image image = e.Item.FindControl("image") as Image;
            foreach (var a in img)
            {
                image.ImageUrl = "~/images/Product/" + a.NameImg;
            }
        }
    }
}